package freespiritsocial.io.user.viewmodel.delegates

import freespiritsocial.io.user.event.EventViewModel
import freespiritsocial.io.user.network.apiService
import me.hgj.jetpackmvvm.base.BaseApp
import me.hgj.jetpackmvvm.base.appContext
import me.hgj.jetpackmvvm.ext.request

/**
 * IPostApi 代理实现类
 */
class PostDelegate: IPostApi {
    private val eventViewModel by lazy {
        (appContext as BaseApp).getAppViewModelProvider().get(EventViewModel::class.java)
    }

    override fun saveInvitation(id: Long?) {
        eventViewModel.request({
            apiService.saveInvitation(id)
        },{
            eventViewModel.savePostEvent.postValue(id)
        },isShowDialog = true)
    }

    override fun hideInvitation(id: Long?) {
        eventViewModel.request({
            apiService.hideInvitation(id)
        },{
            eventViewModel.hidePostEvent.postValue(id)
        },isShowDialog = true)
    }

    override fun delInvitation(id: Long?) {
        eventViewModel.request({
            apiService.deleteInvitation(id)
        },{
            eventViewModel.delPostEvent.postValue(id)
        })
    }

    override fun likePost(id: Long?) {
        eventViewModel.request({
            apiService.likePost(id)
        },{
            eventViewModel.likePostEvent.postValue(id)
        },isShowDialog = true)
    }

    override fun reportInvitation(id: Long?,type: Int) {
        eventViewModel.request({
            apiService.reportInvitation(id,type)
        },{
            eventViewModel.toast.postValue("The report information has been successfully sent to the administrator")
        })
    }
}